from RandomList import GetRandomList

def heapify(arr, n, i): 
    smallest  = i  
    l = 2 * i + 1     
    r = 2 * i + 2     
    if l < n and arr[i] > arr[l]: 
        smallest  = l 
    if r < n and arr[smallest] > arr[r]: 
        smallest  = r 
    if smallest  != i: 
        arr[i],arr[smallest] = arr[smallest],arr[i]  
        heapify(arr, n, smallest) 

def min_heap_sort(arr): 
    n = len(arr) 
    # Build a maxheap. 
    for i in range(n, -1, -1): 
        heapify(arr, n, i) 
    for i in range(n-1, 0, -1): 
        arr[i], arr[0] = arr[0], arr[i]   
        heapify(arr, i, 0) 
    return arr
  

if __name__ == "__main__":
    Arr = GetRandomList(100)
    Arr = min_heap_sort(Arr)
    print(Arr)
    
    




